<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>计算属性的 getter 和 setter</title>
</head>
<body>
<div id="app">
    <H1>姓：{{ familyName }}</H1>
    <H1>名：{{ givenName }}</H1>

    <h1>姓名：{{ fullName }}</h1>
</div>

<script type="module">
    import {createApp, ref, computed} from "../../../js/vue.esm-browser.js";

    let app = createApp(
        {
            setup() {
                let familyName = ref("kevin")
                let givenName = ref("abcque")
                // 问题：这样写是没有办法通过修改 fullNane 来更新 familyName 和 givenName
                // let fullName = computed(
                //     () => {
                //         return familyName.value + " " + givenName.value
                //     }
                // )

                let fullName = computed(
                    {
                        get:function () {
                            return familyName.value + " " + givenName.value
                        },
                        set:function (name) {
                            let split = name.split(" ");
                            familyName.value = split[0]
                            givenName.value = split[1]
                        }
                    }
                )
                return {
                    familyName, givenName, fullName
                }
            }
        }
    );

    app.mount("#app")
</script>
</body>
</html>